/**
 * @param {number} num
 * @return {string}
 */
var intToRoman = function (num) {
  let data = {
    1000: 'M',
    900: 'CM',
    500: 'D',
    400: 'CD',
    100: 'C',
    90: 'XC',
    50: 'L',
    40: 'XL',
    10: 'X',
    9: 'IX',
    5: 'V',
    4: 'IV',
    1: 'I'
  }
  let index = 1000
  let ROMNUM = ''
  let nums = num
  let count = 0
  while (count < 4) {
    let all = Math.floor(nums / index)
    if ([1, 4, 5, 9].includes(all)) {
      ROMNUM += data[all * index]
    } else if (all > 5 && all < 9) {
      ROMNUM += data[5 * index]
      for (let i = 0; i < all - 5; i++) {
        ROMNUM += data[1 * index]
      }
    } else if (all > 1 && all < 4) {
      for (let i = 0; i < all; i++) {
        ROMNUM += data[1 * index]
      }
    }
    nums = nums - all * index
    index = index / 10
    count++
  }
  return ROMNUM
}
console.log(intToRoman(58))
